package com.youan.serve.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youan.pangu.base.util.PrimaryKeyUtil;
import com.youan.serve.controller.swagger.SyscodeControllerSwagger;
import com.youan.serve.dao.domain.Log;
import com.youan.serve.dao.domain.Syscode;
import com.youan.serve.service.ISyscodeService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author auto_code
 * @since 2020-02-29
 */
@Controller
@RequestMapping("/syscode")
public class SyscodeController implements SyscodeControllerSwagger{
    @Autowired
    private ISyscodeService syscodeService;

    @Override
    @PostMapping("/syscode")
    public Syscode addSyscode(Syscode syscode) throws Exception {
        syscode.setCodeId(PrimaryKeyUtil.getCommonId());
        syscodeService.save(syscode);
        return syscode;
    }

    @Override
    @PutMapping("/syscode")
    public Syscode updateSyscode(Syscode syscode){
        syscodeService.updateById(syscode);
        return syscode;
    }

    @Override
    @GetMapping("/syscodes")
    public List<Syscode> selectAllSyscode(){
        return syscodeService.list();
    }

    @Override
    @DeleteMapping("/syscode/{codeId}")
    public void deleteSyscodeByCodeId(@PathVariable String codeId){
        syscodeService.removeById(codeId);
    }

    @Override
    @GetMapping("/syscode/{codeId}")
    public Syscode selectSyscodeByCodeId(@PathVariable String codeId){
        return syscodeService.getById(codeId);
    }

    @Override
    @DeleteMapping("/deleteSysCodeAndSysCodeDetailsBySysCodeId/{sysCodeId}")
    public void deleteSysCodeAndSysCodeDetailsBySysCodeId(@PathVariable String sysCodeId) {
        syscodeService.deleteSysCodeAndSysCodeDetailsBySysCodeId(sysCodeId);
    }

    @Override
    @GetMapping("/syscodes/pageable")
    public Page<Syscode> getSyscodePageable(Page page) {
        return syscodeService.page(page);
    }

    @Override
    @GetMapping("/syscodes/example")
    public List<Syscode> selectSyscodesByExample(Syscode syscode) {
        QueryWrapper<Syscode> wrapper = new QueryWrapper<>(syscode);
        return syscodeService.list(wrapper);
    }

}

